GSList *connected;
gboolean with_separators;
gint n_items;
+ gchar *action_namespace;
} GtkModelMenuBinding;
static void
gpointer user_data);
static void gtk_model_menu_binding_append_model (GtkModelMenuBinding *binding,
GMenuModel *model,
+ const gchar *action_namespace,
gboolean with_separators);
static void
}
g_object_unref (binding->model);
+ g_free (binding->action_namespace);
g_slice_free (GtkModelMenuBinding, binding);
}
static void
gtk_model_menu_binding_append_item (GtkModelMenuBinding *binding,
GMenuModel *model,
+ const gchar *action_namespace,
gint item_index,
gchar **heading)
{
if ((section = g_menu_model_get_item_link (model, item_index, "section")))
{
+ const gchar *section_namespace = NULL;
+
g_menu_model_get_item_attribute (model, item_index, "label", "s", heading);
- gtk_model_menu_binding_append_model (binding, section, FALSE);
+ g_menu_model_get_item_attribute (model, item_index, "action-namespace", "s", §ion_namespace);
+
+ if (action_namespace)
+ {
+ gchar *namespace = g_strjoin (".", action_namespace, section_namespace, NULL);
+ gtk_model_menu_binding_append_model (binding, section, namespace, FALSE);
+ g_free (namespace);
+ }
+ else
+ {
+ gtk_model_menu_binding_append_model (binding, section, section_namespace, FALSE);
+ }
+
+ g_free (section_namespace);
g_object_unref (section);
}
else
{
GtkMenuItem *item;
- item = gtk_model_menu_item_new (model, item_index, binding->accels);
+ item = gtk_model_menu_item_new (model, item_index, action_namespace, binding->accels);
gtk_menu_shell_append (binding->shell, GTK_WIDGET (item));
gtk_widget_show (GTK_WIDGET (item));
binding->n_items++;
static void
gtk_model_menu_binding_append_model (GtkModelMenuBinding *binding,
GMenuModel *model,
+ const gchar *action_namespace,
gboolean with_separators)
{
gint n, i;
gint our_position = binding->n_items;
gchar *heading = NULL;
- gtk_model_menu_binding_append_item (binding, model, i, &heading);
+ gtk_model_menu_binding_append_item (binding, model, action_namespace, i, &heading);
if (with_separators && our_position < binding->n_items)
{
binding->n_items = 0;
/* add new items from the model */
- gtk_model_menu_binding_append_model (binding, binding->model, binding->with_separators);
+ gtk_model_menu_binding_append_model (binding, binding->model, binding->action_namespace, binding->with_separators);
}
static gboolean
static void
gtk_model_menu_bind (GtkMenuShell *shell,
GMenuModel *model,
+ const gchar *action_namespace,
gboolean with_separators)
{
GtkModelMenuBinding *binding;
binding->update_idle = 0;
binding->connected = NULL;
binding->with_separators = with_separators;
+ binding->action_namespace = g_strdup (action_namespace);
g_object_set_data_full (G_OBJECT (shell), "gtk-model-menu-binding", binding, gtk_model_menu_binding_free);
}
GtkWidget *
gtk_model_menu_create_menu (GMenuModel *model,
+ const gchar *action_namespace,
GtkAccelGroup *accels)
{
GtkWidget *menu;
menu = gtk_menu_new ();
gtk_menu_set_accel_group (GTK_MENU (menu), accels);
- gtk_model_menu_bind (GTK_MENU_SHELL (menu), model, TRUE);
+ gtk_model_menu_bind (GTK_MENU_SHELL (menu), model, action_namespace, TRUE);
gtk_model_menu_populate (GTK_MENU_SHELL (menu), accels);
return menu;
GtkWidget *menu;
menu = gtk_menu_new ();
- gtk_model_menu_bind (GTK_MENU_SHELL (menu), model, TRUE);
+ gtk_model_menu_bind (GTK_MENU_SHELL (menu), model, NULL, TRUE);
gtk_model_menu_populate (GTK_MENU_SHELL (menu), NULL);
return menu;
menubar = gtk_menu_bar_new ();
- gtk_model_menu_bind (GTK_MENU_SHELL (menubar), model, FALSE);
+ gtk_model_menu_bind (GTK_MENU_SHELL (menubar), model, NULL, FALSE);
gtk_model_menu_populate (GTK_MENU_SHELL (menubar), accels);
return menubar;
menubar = gtk_menu_bar_new ();
- gtk_model_menu_bind (GTK_MENU_SHELL (menubar), model, FALSE);
+ gtk_model_menu_bind (GTK_MENU_SHELL (menubar), model, NULL, FALSE);
gtk_model_menu_populate (GTK_MENU_SHELL (menubar), NULL);
return menubar;
->draw_indicator (check_item, cr);
}
+static void
+gtk_actionable_set_namespaced_action_name (GtkActionable *actionable,
+ const gchar *namespace,
+ const gchar *action_name)
+{
+ if (namespace)
+ {
+ gchar *name = g_strdup_printf ("%s.%s", namespace, action_name);
+ gtk_actionable_set_action_name (actionable, name);
+ g_free (name);
+ }
+ else
+ {
+ gtk_actionable_set_action_name (actionable, action_name);
+ }
+}
+
static void
gtk_model_menu_item_setup (GtkModelMenuItem *item,
GMenuModel *model,
gint item_index,
+ const gchar *action_namespace,
GtkAccelGroup *accels)
{
GMenuAttributeIter *iter;
if ((submenu = g_menu_model_get_item_link (model, item_index, "submenu")))
{
- gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), gtk_model_menu_create_menu (submenu, accels));
+ gchar *section_namespace = NULL;
+ GtkWidget *menu;
+
+ g_menu_model_get_item_attribute (model, item_index, "action-namespace", "s", §ion_namespace);
+
+ if (action_namespace)
+ {
+ gchar *namespace = g_strjoin (".", action_namespace, section_namespace, NULL);
+ menu = gtk_model_menu_create_menu (submenu, namespace, accels);
+ g_free (namespace);
+ }
+ else
+ {
+ menu = gtk_model_menu_create_menu (submenu, section_namespace, accels);
+ }
+
+ gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), menu);
+
+ g_free (section_namespace);
g_object_unref (submenu);
}
gtk_menu_item_set_label (GTK_MENU_ITEM (item), g_variant_get_string (value, NULL));
else if (g_str_equal (key, "action") && g_variant_is_of_type (value, G_VARIANT_TYPE_STRING))
- gtk_actionable_set_action_name (GTK_ACTIONABLE (item), g_variant_get_string (value, NULL));
+ gtk_actionable_set_namespaced_action_name (GTK_ACTIONABLE (item), action_namespace,
+ g_variant_get_string (value, NULL));
else if (g_str_equal (key, "target"))
gtk_actionable_set_action_target_value (GTK_ACTIONABLE (item), value);
GtkMenuItem *
gtk_model_menu_item_new (GMenuModel *model,
gint item_index,
+ const gchar *action_namespace,
GtkAccelGroup *accels)
{
GtkModelMenuItem *item;
item = g_object_new (GTK_TYPE_MODEL_MENU_ITEM, NULL);
- gtk_model_menu_item_setup (item, model, item_index, accels);
+ gtk_model_menu_item_setup (item, model, item_index, action_namespace, accels);
return GTK_MENU_ITEM (item);
}